home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / status / omnimoni.0 / omnimoni / OmniMoni / install.tcl < prev    next >
Encoding:
Text File  |  1995-11-12  |  9.2 KB  |  315 lines

  1. #!/usr/local/bin/tclsh
  2.  
  3. proc FindExec { what } {
  4.     set error [catch "exec whereis $what" path]
  5.     if {$error || [llength $path] == 1} {
  6.     Blurb "I can't seem to find out where $what is, please tell me:" 0
  7.     set ret_path [GetPath $what]
  8.     } else {
  9.     if {[llength $path] > 2} {
  10.         Blurb "I found $what at [expr [llength $path] - 1] different \
  11.             places, please tell me which one you want." 0
  12.         Blurb "" 0
  13.         set temp [lrange $path 1 end]
  14.         set count 1
  15.         foreach item $temp {
  16.         Blurb "$count.  $item" 3
  17.         incr count
  18.         }
  19.         set which "dummy"
  20.         while {[catch "expr $which + 1"] || $which != [expr int($which)] \
  21.             || $which < 0 || $which > [llength $temp]} {
  22.         puts -nonewline "\nWhich? "
  23.         gets stdin which
  24.         }
  25.         set ret_path [lindex $temp [expr $which - 1]]
  26.     } else {
  27.         set ret_path [lindex $path 1]
  28.         Blurb "I found $what at $ret_path." 0
  29.         puts -nonewline "\nIs that okay (y/n)? "
  30.         gets stdin okay
  31.         if {$okay != "y"} {
  32.         set ret_path [GetPath $what]
  33.         }
  34.     }
  35.     Blurb "" 0
  36.     Blurb "Okay, we'll use the $what in $ret_path." 0
  37.     }
  38.     return $ret_path
  39. }
  40.  
  41. proc GetPath { what } {
  42.     set error 1
  43.     while {$error} {
  44.     Blurb "" 0
  45.     Blurb "I see, you don't like that $what...okay, which one \
  46.         would you like to use?" 0
  47.     puts -nonewline "\nWhere? "
  48.     gets stdin path
  49.     Blurb "" 0
  50.     Blurb "" 0
  51.     set error 0
  52.     if {[file exists $path]} {
  53.         Blurb "Okay, I see, there is a $what at $path." 0
  54.     } else {
  55.         Blurb "Oops, I don't see a $what at $path." 0
  56.         set error 1
  57.     }
  58.     if {[file executable $path]} {
  59.         Blurb "Good, $path is also executable." 0
  60.     } else {
  61.         Blurb "Uh-oh, $path isn't executable." 0
  62.         set error 1
  63.     }
  64.     if {$error} {
  65.         Blurb "" 0
  66.         Blurb "There seemed to have been a problem, do you want \
  67.             to use that $path anyway?" 0
  68.         puts -nonewline "\nOkay (y/n)? "
  69.         gets stdin temp
  70.         if {$temp == "y"} {
  71.         set error 0
  72.         }
  73.     }
  74.     }
  75.     return $path
  76. }
  77.  
  78. proc Blurb { message indent } {
  79.     if {![catch {set size [exec stty size]}]} {
  80.     # if the stty command worked
  81.     set columns [lindex $size 1]
  82.     } else {    
  83.     set columns 80
  84.     }
  85.     # a little margin for readability
  86.     incr columns -2
  87.     set line ""
  88.     set space ""
  89.     for {set i 0} {$i < abs($indent)} {incr i} {
  90.     # generate the string of spaces for indention
  91.     set space "$space "
  92.     }
  93.     foreach word $message {
  94.     if {[string length $line] + [string length $word] < $columns} {
  95.         set line "$line$word "
  96.     } else {
  97.         puts $line
  98.         set line "$space$word "
  99.     }
  100.     }
  101.     puts $line
  102. }
  103.  
  104.  
  105.  
  106.  
  107. Blurb "This script will ask you for some information and then install \
  108.     OmniMoni accordingly.  Note that this script is not particularly \
  109.     robust regarding error checking, so please don't try to break it." 0
  110. Blurb "" 0
  111. Blurb "" 0
  112. Blurb "Which of these would you like to do?" 0
  113. Blurb "" 0
  114. Blurb "1.  Do a real installation, quietly.  This assumes wish is in \
  115.     /usr/local/bin and will install the binary in \
  116.     /usr/local/bin and support files in /usr/local/lib/omnimoni and the \
  117.     man page in /usr/local/man/man1/omnimoni.1." 4
  118. Blurb "2.  Do a real installation, verbosely." 4
  119. Blurb "3.  Just find out what would be copied where if I was doing a real \
  120.     installation." 3
  121. puts -nonewline "\nType: "
  122. gets stdin type
  123. if {$type == 1} {
  124.     set VERBOSE 0
  125.     set INSTALL 1
  126. } elseif {$type == 2} {
  127.     set VERBOSE 1
  128.     set INSTALL 1
  129. } else {
  130.     set VERBOSE 1
  131.     set INSTALL 0
  132.     set type 3
  133. }
  134.  
  135. set wish_path "/usr/local/bin/wish"
  136. if {$VERBOSE} {
  137.     Blurb "" 0
  138.     Blurb "" 0
  139.     Blurb "Okay then, we will do a type $type installation.  Now I'm going to \
  140.         try to figure out some stuff about your system and ask you to \
  141.         verify it.  If you enter any directories, they can not be local \
  142.         to here and they can not use any special characters like ~ \
  143.         (tilde)." 0
  144.     Blurb "" 0
  145.     Blurb "" 0
  146.     set wish_path [FindExec wish]
  147. }
  148.  
  149.  
  150. set bin_path ""
  151. if {$VERBOSE} {
  152.     Blurb "" 0
  153.     Blurb "" 0
  154.     Blurb "Next I need to know where to install the OmniMoni executable.  \
  155.         I'll create the directory and the path above it if either don't \
  156.         exist." 0
  157.     puts -nonewline "\nWhere \[/usr/local/bin\]? "
  158.     gets stdin bin_path
  159. }
  160. if {$bin_path == ""} {
  161.     set bin_path "/usr/local/bin"
  162. }
  163.  
  164. set pics "both"
  165. if {$VERBOSE} {
  166.     Blurb "" 0
  167.     Blurb "" 0
  168.     Blurb "Next I need to know if you want to install the support files. \
  169.         They are two GIF pictures and are 100% \
  170.         unnecessary and fluff.  If you don't want them everything will \
  171.         still work just fine.  They are about 95k and 10k." 0
  172.     Blurb "" 0
  173.     Blurb "1.  I want both because I like beautifully ray-traced pictures to \
  174.         show up when OmniMoni starts and to entertain me if a window is \
  175.         otherwise empty."  3
  176.     Blurb "2.  I just want the big one." 3
  177.     Blurb "3.  I just want the little one." 3
  178.     Blurb "4.  I don't want any of 'em." 3
  179.     unset pics
  180.     puts -nonewline "\nWhich? "
  181.     gets stdin which
  182.     if {$which == 1} {
  183.     set pics "both"
  184.     } elseif {$which == 2} {
  185.     set pics "big"
  186.     } elseif {$which == 3} {
  187.     set pics "small"
  188.     } else {
  189.     set pics "none"
  190.     }
  191. }
  192.  
  193. set lib_path "/usr/local/lib/omnimoni"
  194. if {$VERBOSE} {
  195.     if {$pics != "none"} {
  196.     Blurb "" 0
  197.     Blurb "" 0
  198.     Blurb "Great, you choose to go wild and have useless graphics!  Now, \
  199.         where do you want this amazing artwork to go?  Again, I'll \
  200.         create the path if I need to." 0
  201.     puts -nonewline "\nWhere \[/usr/local/lib/omnimoni\]? "
  202.     gets stdin lib_path
  203.     if {$lib_path == ""} {
  204.         set lib_path "/usr/local/lib/omnimoni"
  205.     }
  206.     if {$lib_path != "/usr/local/lib/omnimoni"} {
  207.         Blurb "" 0
  208.         Blurb "Because you did not put the support files at the default \
  209.             place I will create a small script file called \
  210.             \"omnimoni\" which I will put in the binary directory.  \
  211.             This script will set the environmental variable \
  212.             OMNIMONI_LIB to $lib_path and then call real omnimoni." 0
  213.     }
  214.     }
  215. }
  216.  
  217. set man_path "[file dirname $bin_path]/man"
  218. if {$VERBOSE} {
  219.     Blurb "" 0
  220.     Blurb "" 0
  221.     Blurb "Almost done here, the last thing is where to put the man file. \
  222.         I'll take a guess and say you want it at $man_path." 0
  223.     puts -nonewline "\nCorrect (y/n)? "
  224.     gets stdin okay
  225.     if {$okay != "y"} {
  226.     Blurb "" 0
  227.     Blurb "Okay then, where do you want the man file?" 0
  228.     puts -nonewline "\nWhere? "
  229.     gets stdin man_path
  230.     }
  231. }
  232.  
  233. if {$VERBOSE} {
  234.     Blurb "" 0
  235.     Blurb "" 0
  236.     Blurb "" 0
  237.     Blurb "" 0
  238.     Blurb "Here we go..." 0
  239.     Blurb "" 0
  240.     Blurb "Updating file to reflect path changes..." 0
  241. }
  242. if {$INSTALL} {
  243.     if {$lib_path != "/usr/local/lib/omnimoni"} {
  244.     exec echo "\#!/bin/sh" > /tmp/omnimoni
  245.     exec echo "OMNIMONI_LIB=$lib_path" >> /tmp/omnimoni
  246.     exec echo "export OMNIMONI_LIB" >> /tmp/omnimoni
  247.     exec echo "$lib_path/omnimoni.tcl" >> /tmp/omnimoni
  248.     exec echo "\#!$wish_path -f" > /tmp/omnimoni.tcl
  249.     exec cat src/omnimoni.tcl >> /tmp/omnimoni.tcl
  250.     exec install -d -m 755 $lib_path
  251.     exec install -m 555 /tmp/omnimoni.tcl $lib_path
  252.     } else {
  253.     exec echo "\#!$wish_path -f" > /tmp/omnimoni
  254.     exec cat src/omnimoni.tcl >> /tmp/omnimoni
  255.     }
  256. }
  257. if {$VERBOSE} {
  258.     Blurb "Copying OmniMoni to $bin_path/omnimoni with 555 \
  259.         permissions..." 0
  260. }
  261. if {$INSTALL} {
  262.     exec install -d -m 755 $bin_path
  263.     exec install -m 555 /tmp/omnimoni $bin_path
  264.     exec cp man/omnimoni.man.part1 /tmp/omnimoni.1
  265. }
  266. if {$VERBOSE} {
  267.     Blurb "Copying omnimoni.1 to $man_path/omnimoni.1 with 444 \
  268.         permissions..." 0
  269. }
  270. if {$pics != "none"} {
  271.     if {$VERBOSE} {
  272.     Blurb "Copying $pics artwork to $lib_path with 444 permissions..." 0
  273.     }
  274.     if {$INSTALL} {
  275.     if {$pics == "both"} {
  276.         exec install -d -m 755 $lib_path
  277.         exec install -m 444 pics/omnimoni.big.gif $lib_path
  278.         exec install -m 444 pics/omnimoni.small.gif $lib_path
  279.         exec echo ".TP" >> /tmp/omnimoni.1
  280.         exec echo ".BI $lib_path/omnimoni.big.gif" >> /tmp/omnimoni.1
  281.         exec echo "The large picture shown while OmniMoni parses the configuration file." >> /tmp/omnimoni.1
  282.         exec echo ".TP" >> /tmp/omnimoni.1
  283.         exec echo ".BI $lib_path/omnimoni.small.gif" >> /tmp/omnimoni.1
  284.         exec echo "The small picture shown after OmniMoni is done parsing the configuration file." >> /tmp/omnimoni.1
  285.     } elseif {$pics == "big"} {
  286.         exec echo ".TP" >> /tmp/omnimoni.1
  287.         exec echo ".BI $lib_path/omnimoni.big.gif" >> /tmp/omnimoni.1
  288.         exec echo "The large picture shown while OmniMoni parses the configuration file." >> /tmp/omnimoni.1
  289.         exec install -m 444 pics/omnimoni.big.gif $lib_path
  290.     } elseif {$pics == "small"} {
  291.         exec echo ".TP" >> /tmp/omnimoni.1
  292.         exec echo ".BI $lib_path/omnimoni.small.gif" >> /tmp/omnimoni.1
  293.         exec echo "The small picture shown after OmniMoni is done parsing the configuration file." >> /tmp/omnimoni.1
  294.         exec install -m 444 pics/omnimoni.small.gif $lib_path
  295.     }
  296.     }
  297. }
  298. if {$INSTALL} {
  299.     exec cat man/omnimoni.man.part2 >> /tmp/omnimoni.1
  300.     exec install -d -m 755 $man_path/man1
  301.     exec install -m 444 /tmp/omnimoni.1 $man_path/man1
  302.     exec rm -f /tmp/omnimoni /tmp/omnimoni.tcl /tmp/omnimoni.1
  303. }
  304. if {$VERBOSE} {
  305.     Blurb "" 0
  306.     Blurb "" 0
  307.     Blurb "Done.  You should now be able to use OmniMoni.  Don't forget to\
  308.         create a config file.  OmniMoni checks for one in ~/.omnimoni by \
  309.         default, or you can specify a different one with the -f \
  310.         argument." 0
  311.     Blurb "" 0
  312.     Blurb "Have fun." 0
  313. }
  314.  
  315.